
//
//  Created by 卢亚俊
//  Copyright (c) 2022年 All rights reserved.

#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>

@interface UIImage (HTInformation)

//获取图片综合属性
- (NSDictionary *)imageProperty;

- (NSString *)colorModel;

- (UIImageOrientation)Orientation;

- (int)dpiWidth;

- (int)dpiHeight;

- (int)pixelWidth;

- (int)pixelHeight;

- (NSDictionary*)tiffDictonary;

- (NSDictionary*)exifDictionary;
- (UIImage *)renderOrigin;

+ (UIImage *)imageLDNamed:(NSString *)name;
+ (UIImage *)imageLDBGNamed:(NSString *)name;
+ (UIImage *)imageLDBGFILLNamed:(NSString *)name;

- (NSString *)getImageSizeMB;

//将图片进行等比例缩放
- (UIImage *)scaleImageMaxwidth:(float)maxwidth maxheight:(float)maxheight;

//指定宽度按比例缩放
-(UIImage *) imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth;

//压缩图片 最大宽高为 1024 1024
-(UIImage *) compressImage;
/**
 *  @brief  图片大于多少KB会进行压缩
 */
+(UIImage*)compressedImageToLimitSizeOfKB:(CGFloat)kb image:(UIImage*)image;

/**  压缩图片*/
+ (UIImage *)imageWithOriginalImage:(UIImage *)image;
/**
 *从图片中按指定的位置大小截取图片的一部分
 * UIImage image 原始的图片
 * CGRect rect 要截取的区域
 */
- (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect ;
//按比例缩放,size 是你要把图显示到 多大区域 CGSizeMake(300, 140)
-(UIImage *) imageCompressForSize:(UIImage *)sourceImage targetSize:(CGSize)size;
/*
 *  压缩图片方法(先压缩质量再压缩尺寸)
 */
-(NSData *)compressWithLengthLimit:(NSUInteger)maxLength;
/*
 *  压缩图片方法(压缩质量)
 */
-(NSData *)compressQualityWithLengthLimit:(NSInteger)maxLength;
/*
 *  压缩图片方法(压缩质量二分法)
 */
-(NSData *)compressMidQualityWithLengthLimit:(NSInteger)maxLength;
/*
 *  压缩图片方法(压缩尺寸)
 */
-(NSData *)compressBySizeWithLengthLimit:(NSUInteger)maxLength;


//保持原来的长宽比，生成一个缩略图
+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize;
- (UIImage *)gaussianBlur;
- (UIImage *)edgeDetection;
- (UIImage *)emboss;
- (UIImage *)sharpen;
- (UIImage *)unsharpen;

- (UIImage *)fixOrientation;

// Geometric Operations
- (UIImage *)rotateInRadians:(float)radians;
- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha;
/**
 *  剪切图片为正方形
 *
 *  @param image   原始图片比如size大小为(400x200)pixels
 *  @param newSize 正方形的size比如400pixels
 *
 *  @return 返回正方形图片(400x400)pixels
 */
- (UIImage *)squareImageFromImage:(UIImage *)image scaledToSize:(CGFloat)newSize;    

/**
 生成自定义样式二维码
 注意：有些颜色结合生成的二维码识别不了
 @param codeString 字符串
 @param size 大小
 @param backColor 背景色
 @param frontColor 前景色
 @param centerImage 中心图片
 @return image二维码
 */
+ (UIImage *)createQRCodeImageWithString:( NSString *)codeString andSize:(CGSize)size andBackColor:( UIColor *)backColor andFrontColor:( UIColor *)frontColor andCenterImage:( UIImage *)centerImage;
+ (UIImage *)createQRCodeImageWithString:( NSString *)codeString  andSize:(CGSize)size andCenterImage:(UIImage *)centerImage;;
+ (UIImage *)createQRCodeImageWithString:( NSString *)codeString andSize:(CGSize)size;


+(void)createQRCodeImageWithString:(NSString *)codeString andSize:(CGSize)size complent:(void(^)(UIImage *img))complent;
/**
 生成条形码

 @param text 字符串
 @param size 大小
 @return 返回条码图像
 */
+ (UIImage*)createBarCodeWithString:(NSString*)text QRSize:(CGSize)size;

//根据一个View生成一个image
+ (UIImage *)viewToImage:(UIView *)view;

-(UIImage *)imageByResizeToSize:(CGSize)size;

/**
 *  截取当前屏幕
 *
 *  @return NSData *
 */
+ (NSData *)dataWithScreenshotInPNGFormat;
/**
 *  返回截取到的图片
 *
 *  @return UIImage *
 */
+ (UIImage *)imageWithScreenshot;

/** 识别图片中二维码 */
- (void)detectorImageSuccess:(void (^)(NSString *messageString))success failer:(void(^)(void))failer;

/// 对图片进行模糊处理
/// @param blur 模糊等级
- (UIImage *)tg_blurryBlurLevel:(CGFloat)blur;
/** 通过色值生成图片 */
+ (instancetype)createImageWithColor:(UIColor *)color size:(CGSize)size;

/// 二维码中心添加logo
/// @param image1 二维码图片
/// @param image2 logo图片
/// @param centerSize logo大小
+ (instancetype)createImageWithImage:(UIImage *)image1 centerImage:(UIImage *)image2 centerSize:(CGSize)centerSize;
@end
